View Javadoc
1 /* 2 * (C) 2002 David Carr david@carr.name 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 19 package net.sourceforge.mflow.config; 20 21 import java.awt.Button; 22 import java.awt.Component; 23 import java.awt.Dialog; 24 import java.awt.Dimension; 25 import java.awt.Insets; 26 import java.awt.Window; 27 import java.awt.event.ActionEvent; 28 import java.awt.event.ActionListener; 29 import java.awt.event.WindowAdapter; 30 import java.awt.event.WindowEvent; 31 import java.beans.PropertyEditor; 32 33 /*** 34 * Class to open a custom editor in a seperate window 35 * 36 * @author <a href="mailto:david@carr.name">David Carr</a> 37 * @version $Revision: 1.4 $ 38 */ 39 class PropertyDialog extends Dialog implements ActionListener { 40 /*** 41 * Private reference to the done button 42 */ 43 private Button doneButton; 44 /*** 45 * Private reference to the custom editor 46 */ 47 private Component customEditor; 48 /*** 49 * Constant for the vertical padding 50 */ 51 private final static int vPad = 5; 52 /*** 53 * Constant for the horizontal padding 54 */ 55 private final static int hPad = 4; 56 57 /*** 58 * Constructor 59 * 60 * @param frame the owner of the dialog 61 * @param pe the property editor 62 * @param x the x coordinate 63 * @param y the y coordinate 64 */ 65 PropertyDialog(Window frame, PropertyEditor pe, int x, int y) { 66 super((Dialog) frame, pe.getClass().getName(), true); 67 this.addWindowListener(new WindowAdapter() { 68 /*** 69 * Disposes of the window 70 * 71 * @param e the event 72 */ 73 public void windowClosing(WindowEvent e) { 74 e.getWindow().dispose(); 75 } 76 }); 77 setLayout(null); 78 79 this.customEditor = pe.getCustomEditor(); 80 add(this.customEditor); 81 82 this.doneButton = new Button("Done"); 83 this.doneButton.addActionListener(this); 84 add(this.doneButton); 85 86 setLocation(x, y); 87 setVisible(true); 88 } 89 90 /*** 91 * Called when the done button is pressed 92 * 93 * @param evt the event 94 */ 95 public void actionPerformed(ActionEvent evt) { 96 dispose(); 97 } 98 99 /*** 100 * Lays out the components 101 */ 102 public void doLayout() { 103 Insets ins = getInsets(); 104 Dimension bodySize = this.customEditor.getPreferredSize(); 105 Dimension buttonSize = this.doneButton.getPreferredSize(); 106 107 int width = ins.left + 2 * hPad + ins.right + bodySize.width; 108 int height = 109 ins.top + 3 * vPad + ins.bottom + bodySize.height + buttonSize.height; 110 111 this.customEditor.setBounds( 112 ins.left + hPad, 113 ins.top + vPad, 114 bodySize.width, 115 bodySize.height); 116 117 this.doneButton.setBounds( 118 (width - buttonSize.width) / 2, 119 ins.top + (2 * hPad) + bodySize.height, 120 buttonSize.width, 121 buttonSize.height); 122 123 setSize(width, height); 124 } 125 }

This page was automatically generated by Maven